package com.ascent.dao;

import com.ascent.classes.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface UserMapper {
    /*
     *登录
     * @Method login
     * @Date 2022/11/2 17:19
     */
    @Select("select * from productuser where username=#{username} and password=#{password}")
    User login(@Param("username") String username,@Param("password") String password);

    //@Insert("insert into ascent.usr values (null,#{username},#{password},#{companyname},#{city},#{job},#{tel},#{email},#{country},#{zip},#{companyaddress},#{superuser},#{note},#{fullname},#{title})")
    @Insert("insert into productuser(username,password,companyname,city,job,tel,email,country,zip,companyaddress,del_flag,superuser) values(#{username},#{password},#{companyname},#{city},#{job},#{tel},#{email},#{country},#{zip},#{companyaddress},#{del_flag},#{superuser})")
    @ResultMap("userResultMap")
    void add(User user);

    @Select("select del_flag from productuser where username=#{username}")
    int selectFlag(String username);

    /*
     *查询所有
     * @Method selectAll
     * @Date 2022/11/2 17:19
     */
    @Select("select * from productuser")
    @ResultMap("userResultMap")
    List<User> selectAll();
    /*
     *根据用户查所有
     * @Method selectById
     * @Date 2022/11/2 21:16
     */
    @Select("select * from productuser where username=#{username}")
    @ResultMap("userResultMap")
    User selectByUser(String username);
    /*
     *根据id查询数据
     */
    @Select("select * from productuser where uid=#{uid}")
    @ResultMap("userResultMap")
    User selectByUid(int uid);


    /*
     *修改数据
     * @Method updateUser
     * @Date 2022/11/3 9:54
     */
    @Update("update productuser set city=#{city},username=#{username},password=#{password},companyname=#{companyname},job=#{job},tel=#{tel},email=#{email},country=#{country},zip=#{zip},companyaddress=#{companyaddress},note=#{note},fullname=#{fullname},title=#{title}, superuser=#{superuser},del_flag=#{del_flag} where uid=#{uid}")
    @ResultMap("userResultMap")
    void updateUser(User user);

    /*
     *根据用户查权限
     * @Method selectById
     * @Date 2022/11/2 21:16
     */
    @Select("select superuser from productuser where username=#{username}")
    @ResultMap("userResultMap")
    User selectSuperByUser(String username);

    /*
     *修改权限
     * @Method updateUser
     * @Date 2022/11/3 9:54
     */
    @Update("update productuser set superuser=#{superuser} where username=#{username}")
    @ResultMap("userResultMap")
    void updateSuper(@Param("username") String username,@Param("superuser") String superuser);

    @Update("update productuser set del_flag=#{del_flag} where username=#{username}")
    @ResultMap("userResultMap")
    void updateFlag(@Param("username") String username,@Param("del_flag") int del_flag);

}
